<?php
/*
 * @Author: your name
 * @Date: 2021-11-04 11:14:43
 * @LastEditTime: 2022-01-14 13:48:47
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \property\app\Http\Middleware\CheckShopToken.php
 */

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use  App\Http\Controllers\redis\RedisController as Redis;
class CheckShopToken
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
         $header = $_SERVER;
        if( !isset($header['TOKEN'])){
               return   abort(400);
        }else{
             $token =  $header['TOKEN'];
             $key = SHOP_LOGIN_REDIS_KEY.$token;
            if($token && Redis::existSKey($key,['RedisDB'=>12])){
                Redis::expire( $key,7*24*3600,['RedisDB'=>12]);          //重置登录时间
            }else{
                toJson(0, '登录已过期');
            }
        }
        return $next($request);
    }
}
